package com.fbty.mt.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLConnection;

import com.fbty.mt.domain.CheckInfo;
import com.fbty.mt.service.ProxyService;
import com.fbty.mt.service.impl.ProxyServiceImpl;


public class Demo {

	/**
	 * Description: <br>
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		Demo demo = new Demo();
		demo.doPost();
	}
	
public static void doPost() throws IOException{
		
		URL url = new URL("http://212.68.244.46:5160/account");
    	Authenticator.setDefault(new BasicAuthenticator("admin", "363636"));
        URLConnection conn;
        conn = url.openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        
        StringBuffer param = new StringBuffer();   
        param.append("edit=1");
        param.append("&");
        param.append("autodisable=1");
        param.append("&");
        param.append("enable=1");
        param.append("&");
        param.append("usepassword=1");
        param.append("&");
        param.append("enablesocks=1");
        param.append("&");
        param.append("enablewww=0");
        param.append("&");
        param.append("enabletelnet=0");
        param.append("&");
        param.append("enabledial=0");
        param.append("&");
        param.append("enableftp=0");
        param.append("&");
        param.append("enableothers=0");
        param.append("&");
        param.append("enablemail=0");
        param.append("&");
        param.append("username=test");
        param.append("&");
        param.append("password=123123");
        param.append("&");
        param.append("connection=-1");
        param.append("&");
        param.append("bandwidth=-1");
        param.append("&");
        param.append("disabledate=2013-01-31");
        param.append("&");
        param.append("disabletime=20:00:00");
        param.append("&");
        param.append("userid=1");
        
        String data=param.toString();
        
        wr.write(data);
        wr.flush(); 
        // Get the response 
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(),"gbk")); 
        String line;
        while ((line = rd.readLine()) != null) { 
           System.out.println(line);
            } 
        wr.close(); 
        rd.close(); 

	}

}


class BasicAuthenticator extends Authenticator {
    String userName;
    String password;

    public BasicAuthenticator(String userName, String password) {
        this.userName = userName;
        this.password = password;
    }

    /**
     * Called when password authorization is needed.  Subclasses should
     * override the default implementation, which returns null.
     *
     * @return The PasswordAuthentication collected from the
     *         user, or null if none is provided.
     */
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(userName, password.toCharArray());
    }
}